using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using Unity.Mathematics;
using UnityEngine;

public class MageController : PlayerController
{
    public GameObject magicPrefab;
    public Transform magicStart;
    private GameObject magic;
    public Vector3 targetPos;
    private RaycastHit hitInfo;
    public List<Transform> effectStartist;
    public GameObject effect;
    public GameObject rockMan;


    public override void Awake()
    {
        base.Awake();
        GameManager.Instance.mage = this.gameObject;
        this.gameObject.SetActive(false);
    }


    public void LootToTarget()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        Physics.Raycast(ray, out hitInfo);
        targetPos = hitInfo.point;
        transform.LookAt(hitInfo.point);
    }
    
    public void Magic()
    {
        magic = Instantiate(magicPrefab, magicStart.transform.position,Quaternion.identity);
    }

    public void Skill1Event()
    {
        Instantiate(SkillManager.Instance.SkillListMage.items[0].skillEffect, targetPos, Quaternion.identity);
        SkillManager.Instance.HaveCD[8] = true;
    }

    public void Skill2Event()
    {
        Instantiate(SkillManager.Instance.SkillListMage.items[1].skillEffect, transform.position + (Vector3.up * 10), quaternion.identity);
        SkillManager.Instance.HaveCD[9] = true;
    }

    public void PrepareForSkill3()
    {
        var WaterEquips = GameObject.FindGameObjectsWithTag("CanWater");
        foreach (var WaterEquip in WaterEquips)
        {
            var currentInstance = Instantiate(effect,
                WaterEquip.transform);
            var psUpdater = currentInstance.GetComponent<PSMeshRendererUpdater>();
            psUpdater.UpdateMeshEffect(WaterEquip);
            Destroy(currentInstance,5f);
        }
    }
    public void Skill3Event()
    {
        transform.DOMove(targetPos, 0.2f);
        for (int i = 0; i < 3; i++)
        {
            Instantiate(SkillManager.Instance.SkillListMage.items[2].skillEffect, effectStartist[i]);
        }
        SkillManager.Instance.HaveCD[10] = true;
    }

    public void Skill4Event()
    {
        Instantiate(rockMan, transform.position + Vector3.back * 2, Quaternion.identity);
        SkillManager.Instance.HaveCD[11] = true;
    }

}
